/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-12 上午10:09:40
 *
 * MessageDaoImpl.java
 *
 *******************************************************************/
package com.transer.persistance.dao.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.transer.persistance.bean.Message;
import com.transer.persistance.dao.IMessageDao;
import com.transer.persistance.exception.TranserDatabaseException;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class MessageDaoImpl extends SqlMapClientDaoSupport implements IMessageDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.transer.persistance.dao.IMessageDao#getMessageByID(int)
	 */
	@Override
	public Message getMessageByID(int id) throws TranserDatabaseException {
		try {
			return (Message) getSqlMapClientTemplate().queryForObject("Message.getMessageByID", id);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("getMessageByID error : " + id, e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.transer.persistance.dao.IMessageDao#getMessagesByUser(int)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Message> getMessagesByUser(int userID) throws TranserDatabaseException {
		try {
			return getSqlMapClientTemplate().queryForList("Message.getMessagesByUser", userID);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("getMessagesByUser error : " + userID, e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.transer.persistance.dao.IMessageDao#addMessage(com.transer.persistance
	 * .bean.Message)
	 */
	@Override
	public void addMessage(Message msg) throws TranserDatabaseException {
		try {
			getSqlMapClientTemplate().insert("Message.addMessage", msg);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("addMessage error : " + msg, e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.transer.persistance.dao.IMessageDao#updateMessage(com.transer.persistance
	 * .bean.Message)
	 */
	@Override
	public void updateMessage(Message msg) throws TranserDatabaseException {
		try {
			getSqlMapClientTemplate().update("Message.updateMessage", msg);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("updateMessage error : " + msg, e);
		}
	}

}
